{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/docs/notebooks/00_geemap_key_features.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1",
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
    "<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Create-an-interactive-map\" data-toc-modified-id=\"Create-an-interactive-map-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Create an interactive map</a></span></li><li><span><a href=\"#Add-basemaps\" data-toc-modified-id=\"Add-basemaps-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Add basemaps</a></span></li><li><span><a href=\"#Add-WMS-and-XYZ-tile-layers\" data-toc-modified-id=\"Add-WMS-and-XYZ-tile-layers-3\"><span class=\"toc-item-num\">3&nbsp;&nbsp;</span>Add WMS and XYZ tile layers</a></span></li><li><span><a href=\"#Add-Earth-Engine-data-layers\" data-toc-modified-id=\"Add-Earth-Engine-data-layers-4\"><span class=\"toc-item-num\">4&nbsp;&nbsp;</span>Add Earth Engine data layers</a></span></li><li><span><a href=\"#Search-Earth-Engine-data-catalog\" data-toc-modified-id=\"Search-Earth-Engine-data-catalog-5\"><span class=\"toc-item-num\">5&nbsp;&nbsp;</span>Search Earth Engine data catalog</a></span></li><li><span><a href=\"#Search-Earth-Engine-API-documentation\" data-toc-modified-id=\"Search-Earth-Engine-API-documentation-6\"><span class=\"toc-item-num\">6&nbsp;&nbsp;</span>Search Earth Engine API documentation</a></span></li><li><span><a href=\"#Use-Inspector-tool\" data-toc-modified-id=\"Use-Inspector-tool-7\"><span class=\"toc-item-num\">7&nbsp;&nbsp;</span>Use Inspector tool</a></span></li><li><span><a href=\"#Use-Plotting-tool\" data-toc-modified-id=\"Use-Plotting-tool-8\"><span class=\"toc-item-num\">8&nbsp;&nbsp;</span>Use Plotting tool</a></span></li><li><span><a href=\"#Create-a-split-panel-map\" data-toc-modified-id=\"Create-a-split-panel-map-9\"><span class=\"toc-item-num\">9&nbsp;&nbsp;</span>Create a split-panel map</a></span></li><li><span><a href=\"#Add-marker-cluster\" data-toc-modified-id=\"Add-marker-cluster-10\"><span class=\"toc-item-num\">10&nbsp;&nbsp;</span>Add marker cluster</a></span></li><li><span><a href=\"#Add-customized-legends\" data-toc-modified-id=\"Add-customized-legends-11\"><span class=\"toc-item-num\">11&nbsp;&nbsp;</span>Add customized legends</a></span></li><li><span><a href=\"#Use-Drawing-tools\" data-toc-modified-id=\"Use-Drawing-tools-12\"><span class=\"toc-item-num\">12&nbsp;&nbsp;</span>Use Drawing tools</a></span></li><li><span><a href=\"#Convert-JavaScripts-to-Python\" data-toc-modified-id=\"Convert-JavaScripts-to-Python-13\"><span class=\"toc-item-num\">13&nbsp;&nbsp;</span>Convert JavaScripts to Python</a></span></li><li><span><a href=\"#Use-shapefiles\" data-toc-modified-id=\"Use-shapefiles-14\"><span class=\"toc-item-num\">14&nbsp;&nbsp;</span>Use shapefiles</a></span></li><li><span><a href=\"#Create-Landsat-timelapse\" data-toc-modified-id=\"Create-Landsat-timelapse-15\"><span class=\"toc-item-num\">15&nbsp;&nbsp;</span>Create Landsat timelapse</a></span></li><li><span><a href=\"#Use-time-series-inspector\" data-toc-modified-id=\"Use-time-series-inspector-16\"><span class=\"toc-item-num\">16&nbsp;&nbsp;</span>Use time-series inspector</a></span></li><li><span><a href=\"#Export-images\" data-toc-modified-id=\"Export-images-17\"><span class=\"toc-item-num\">17&nbsp;&nbsp;</span>Export images</a></span></li></ul></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2",
   "metadata": {},
   "source": [
    "Uncomment the following line to install [geemap](https://geemap.org) if needed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# !pip install geemap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5",
   "metadata": {},
   "source": [
    "## Create an interactive map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map(center=(40, -100), zoom=4)\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7",
   "metadata": {},
   "source": [
    "## Add basemaps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.add_basemap(\"HYBRID\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.add_basemap(\"OpenTopoMap\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map.basemap_demo()\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12",
   "metadata": {},
   "source": [
    "## Add WMS and XYZ tile layers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14",
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://viewer.nationalmap.gov/services/\n",
    "url = \"https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}\"\n",
    "Map.add_tile_layer(url, name=\"Google Satellite\", attribution=\"Google\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15",
   "metadata": {},
   "outputs": [],
   "source": [
    "naip_url = \"https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?\"\n",
    "Map.add_wms_layer(\n",
    "    url=naip_url, layers=\"0\", name=\"NAIP Imagery\", format=\"image/png\", shown=True\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16",
   "metadata": {},
   "source": [
    "## Add Earth Engine data layers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add Earth Engine dataset\n",
    "dem = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "landcover = ee.Image(\"ESA/GLOBCOVER_L4_200901_200912_V2_3\").select(\"landcover\")\n",
    "landsat7 = ee.Image(\"LANDSAT/LE7_TOA_5YEAR/1999_2003\")\n",
    "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
    "\n",
    "# Set visualization parameters.\n",
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}\n",
    "\n",
    "# Add Earth Engine layers to Map\n",
    "Map.addLayer(dem, vis_params, \"SRTM DEM\", True, 0.5)\n",
    "Map.addLayer(landcover, {}, \"Land cover\")\n",
    "Map.addLayer(\n",
    "    landsat7, {\"bands\": [\"B4\", \"B3\", \"B2\"], \"min\": 20, \"max\": 200}, \"Landsat 7\"\n",
    ")\n",
    "Map.addLayer(states, {}, \"US States\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19",
   "metadata": {},
   "source": [
    "## Search Earth Engine data catalog"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.search_locations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.search_loc_geom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23",
   "metadata": {},
   "outputs": [],
   "source": [
    "location = Map.search_loc_geom\n",
    "# print(location.getInfo())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24",
   "metadata": {},
   "source": [
    "## Search Earth Engine API documentation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.ee_search()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26",
   "metadata": {},
   "source": [
    "## Use Inspector tool"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "\n",
    "# Add Earth Engine dataset\n",
    "dem = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "landcover = ee.Image(\"ESA/GLOBCOVER_L4_200901_200912_V2_3\").select(\"landcover\")\n",
    "landsat7 = ee.Image(\"LANDSAT/LE7_TOA_5YEAR/1999_2003\")\n",
    "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
    "\n",
    "# Set visualization parameters.\n",
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}\n",
    "\n",
    "# Add Earth Engine layers to Map\n",
    "Map.addLayer(dem, vis_params, \"SRTM DEM\", True, 0.5)\n",
    "Map.addLayer(landcover, {}, \"Land cover\")\n",
    "Map.addLayer(\n",
    "    landsat7, {\"bands\": [\"B4\", \"B3\", \"B2\"], \"min\": 20, \"max\": 200}, \"Landsat 7\"\n",
    ")\n",
    "Map.addLayer(states, {}, \"US States\")\n",
    "\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28",
   "metadata": {},
   "source": [
    "## Use Plotting tool"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "\n",
    "landsat7 = ee.Image(\"LANDSAT/LE7_TOA_5YEAR/1999_2003\").select([0, 1, 2, 3, 4, 6])\n",
    "landsat_vis = {\"bands\": [\"B4\", \"B3\", \"B2\"], \"gamma\": 1.4}\n",
    "Map.addLayer(landsat7, landsat_vis, \"LE7_TOA_5YEAR/1999_2003\")\n",
    "\n",
    "hyperion = ee.ImageCollection(\"EO1/HYPERION\").filter(\n",
    "    ee.Filter.date(\"2016-01-01\", \"2017-03-01\")\n",
    ")\n",
    "hyperion_vis = {\n",
    "    \"min\": 1000.0,\n",
    "    \"max\": 14000.0,\n",
    "    \"gamma\": 2.5,\n",
    "}\n",
    "Map.addLayer(hyperion, hyperion_vis, \"EO1/HYPERION\")\n",
    "\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "30",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.set_plot_options(plot_type=\"bar\", add_marker_cluster=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31",
   "metadata": {},
   "source": [
    "## Create a split-panel map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map.split_map(left_layer=\"HYBRID\", right_layer=\"ROADMAP\")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map.split_map(\n",
    "    left_layer=\"NLCD 2016 CONUS Land Cover\", right_layer=\"NLCD 2001 CONUS Land Cover\"\n",
    ")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34",
   "metadata": {},
   "outputs": [],
   "source": [
    "nlcd_2001 = ee.Image(\"USGS/NLCD/NLCD2001\").select(\"landcover\")\n",
    "nlcd_2016 = ee.Image(\"USGS/NLCD/NLCD2016\").select(\"landcover\")\n",
    "\n",
    "left_layer = geemap.ee_tile_layer(nlcd_2001, {}, \"NLCD 2001\")\n",
    "right_layer = geemap.ee_tile_layer(nlcd_2016, {}, \"NLCD 2016\")\n",
    "\n",
    "Map = geemap.Map()\n",
    "Map.split_map(left_layer, right_layer)\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35",
   "metadata": {},
   "source": [
    "## Add marker cluster"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36",
   "metadata": {},
   "outputs": [],
   "source": [
    "import geemap\n",
    "import json\n",
    "import os\n",
    "import requests\n",
    "from geemap import geojson_to_ee, ee_to_geojson\n",
    "from ipyleaflet import GeoJSON, Marker, MarkerCluster"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38",
   "metadata": {},
   "outputs": [],
   "source": [
    "file_path = os.path.join(os.getcwd(), \"us_cities.json\")\n",
    "\n",
    "if not os.path.exists(file_path):\n",
    "    url = \"https://github.com/gee-community/geemap/raw/master/examples/data/us_cities.json\"\n",
    "    r = requests.get(url)\n",
    "    with open(file_path, \"w\") as f:\n",
    "        f.write(r.content.decode(\"utf-8\"))\n",
    "\n",
    "with open(file_path) as f:\n",
    "    json_data = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39",
   "metadata": {},
   "outputs": [],
   "source": [
    "maker_cluster = MarkerCluster(\n",
    "    markers=[\n",
    "        Marker(location=feature[\"geometry\"][\"coordinates\"][::-1])\n",
    "        for feature in json_data[\"features\"]\n",
    "    ],\n",
    "    name=\"Markers\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.add_layer(maker_cluster)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41",
   "metadata": {},
   "outputs": [],
   "source": [
    "ee_fc = geojson_to_ee(json_data)\n",
    "Map.addLayer(ee_fc, {}, \"US Cities EE\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42",
   "metadata": {},
   "source": [
    "## Add customized legends"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map.add_basemap(\"HYBRID\")\n",
    "landcover = ee.Image(\"USGS/NLCD/NLCD2016\").select(\"landcover\")\n",
    "Map.addLayer(landcover, {}, \"NLCD Land Cover\")\n",
    "Map.add_legend(builtin_legend=\"NLCD\")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map.add_basemap(\"HYBRID\")\n",
    "Map.add_basemap(\"FWS NWI Wetlands\")\n",
    "Map.add_legend(builtin_legend=\"NWI\")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "\n",
    "legend_dict = {\n",
    "    \"11 Open Water\": \"466b9f\",\n",
    "    \"12 Perennial Ice/Snow\": \"d1def8\",\n",
    "    \"21 Developed, Open Space\": \"dec5c5\",\n",
    "    \"22 Developed, Low Intensity\": \"d99282\",\n",
    "    \"23 Developed, Medium Intensity\": \"eb0000\",\n",
    "    \"24 Developed High Intensity\": \"ab0000\",\n",
    "    \"31 Barren Land (Rock/Sand/Clay)\": \"b3ac9f\",\n",
    "    \"41 Deciduous Forest\": \"68ab5f\",\n",
    "    \"42 Evergreen Forest\": \"1c5f2c\",\n",
    "    \"43 Mixed Forest\": \"b5c58f\",\n",
    "    \"51 Dwarf Scrub\": \"af963c\",\n",
    "    \"52 Shrub/Scrub\": \"ccb879\",\n",
    "    \"71 Grassland/Herbaceous\": \"dfdfc2\",\n",
    "    \"72 Sedge/Herbaceous\": \"d1d182\",\n",
    "    \"73 Lichens\": \"a3cc51\",\n",
    "    \"74 Moss\": \"82ba9e\",\n",
    "    \"81 Pasture/Hay\": \"dcd939\",\n",
    "    \"82 Cultivated Crops\": \"ab6c28\",\n",
    "    \"90 Woody Wetlands\": \"b8d9eb\",\n",
    "    \"95 Emergent Herbaceous Wetlands\": \"6c9fb8\",\n",
    "}\n",
    "\n",
    "landcover = ee.Image(\"USGS/NLCD/NLCD2016\").select(\"landcover\")\n",
    "Map.addLayer(landcover, {}, \"NLCD Land Cover\")\n",
    "\n",
    "Map.add_legend(legend_title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46",
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://developers.google.com/earth-engine/datasets/catalog/MODIS_051_MCD12Q1\n",
    "Map = geemap.Map()\n",
    "\n",
    "ee_class_table = \"\"\"\n",
    "\n",
    "Value\tColor\tDescription\n",
    "0\t1c0dff\tWater\n",
    "1\t05450a\tEvergreen needleleaf forest\n",
    "2\t086a10\tEvergreen broadleaf forest\n",
    "3\t54a708\tDeciduous needleleaf forest\n",
    "4\t78d203\tDeciduous broadleaf forest\n",
    "5\t009900\tMixed forest\n",
    "6\tc6b044\tClosed shrublands\n",
    "7\tdcd159\tOpen shrublands\n",
    "8\tdade48\tWoody savannas\n",
    "9\tfbff13\tSavannas\n",
    "10\tb6ff05\tGrasslands\n",
    "11\t27ff87\tPermanent wetlands\n",
    "12\tc24f44\tCroplands\n",
    "13\ta5a5a5\tUrban and built-up\n",
    "14\tff6d4c\tCropland/natural vegetation mosaic\n",
    "15\t69fff8\tSnow and ice\n",
    "16\tf9ffa4\tBarren or sparsely vegetated\n",
    "254\tffffff\tUnclassified\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "landcover = ee.Image(\"MODIS/051/MCD12Q1/2013_01_01\").select(\"Land_Cover_Type_1\")\n",
    "Map.setCenter(6.746, 46.529, 2)\n",
    "Map.addLayer(landcover, {}, \"MODIS Land Cover\")\n",
    "\n",
    "legend_dict = geemap.legend_from_ee(ee_class_table)\n",
    "Map.add_legend(legend_title=\"MODIS Global Land Cover\", legend_dict=legend_dict)\n",
    "\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47",
   "metadata": {},
   "source": [
    "## Use Drawing tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "49",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Add Earth Engine dataset\n",
    "image = ee.Image(\"USGS/SRTMGL1_003\")\n",
    "\n",
    "# Set visualization parameters.\n",
    "vis_params = {\n",
    "    \"min\": 0,\n",
    "    \"max\": 4000,\n",
    "    \"palette\": [\"006633\", \"E5FFCC\", \"662A00\", \"D8D8D8\", \"F5F5F5\"],\n",
    "}\n",
    "\n",
    "# Add Earth Engine DEM to map\n",
    "Map.addLayer(image, vis_params, \"SRTM DEM\")\n",
    "\n",
    "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
    "Map.addLayer(states, {}, \"US States\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.draw_features"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51",
   "metadata": {},
   "source": [
    "## Convert JavaScripts to Python\n",
    "\n",
    "You can simply copy and paste your GEE JavaScripts into a code block wrapped with trip quotes and pass it to a variable. \n",
    "\n",
    "For example, you can grab GEE JavaScripts from [GEE Documentation](https://developers.google.com/earth-engine/image_visualization)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52",
   "metadata": {},
   "outputs": [],
   "source": [
    "js_snippet = \"\"\"\n",
    "// Load an image.\n",
    "var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');\n",
    "\n",
    "// Define the visualization parameters.\n",
    "var vizParams = {\n",
    "  bands: ['B5', 'B4', 'B3'],\n",
    "  min: 0,\n",
    "  max: 0.5,\n",
    "  gamma: [0.95, 1.1, 1]\n",
    "};\n",
    "\n",
    "// Center the map and display the image.\n",
    "Map.setCenter(-122.1899, 37.5010, 10); // San Francisco Bay\n",
    "Map.addLayer(image, vizParams, 'false color composite');\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.js_snippet_to_py(\n",
    "    js_snippet, add_new_cell=True, import_ee=True, import_geemap=True, show_map=True\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap\n",
    "\n",
    "Map = geemap.Map()\n",
    "\n",
    "# Load an image.\n",
    "image = ee.Image(\"LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318\")\n",
    "\n",
    "# Define the visualization parameters.\n",
    "vizParams = {\"bands\": [\"B5\", \"B4\", \"B3\"], \"min\": 0, \"max\": 0.5, \"gamma\": [0.95, 1.1, 1]}\n",
    "\n",
    "# Center the map and display the image.\n",
    "Map.setCenter(-122.1899, 37.5010, 10)\n",
    "# San Francisco Bay\n",
    "Map.addLayer(image, vizParams, \"False color composite\")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap\n",
    "\n",
    "Map = geemap.Map()\n",
    "\n",
    "# Load an image.\n",
    "image = ee.Image(\"LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318\")\n",
    "\n",
    "# Define the visualization parameters.\n",
    "vizParams = {\"bands\": [\"B5\", \"B4\", \"B3\"], \"min\": 0, \"max\": 0.5, \"gamma\": [0.95, 1.1, 1]}\n",
    "\n",
    "# Center the map and display the image.\n",
    "Map.setCenter(-122.1899, 37.5010, 10)\n",
    "# San Francisco Bay\n",
    "Map.addLayer(image, vizParams, \"False color composite\")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap\n",
    "\n",
    "Map = geemap.Map()\n",
    "ee.Initialize()\n",
    "\n",
    "# Load an image.\n",
    "image = ee.Image(\"LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318\")\n",
    "\n",
    "# Define the visualization parameters.\n",
    "vizParams = {\"bands\": [\"B5\", \"B4\", \"B3\"], \"min\": 0, \"max\": 0.5, \"gamma\": [0.95, 1.1, 1]}\n",
    "\n",
    "# Center the map and display the image.\n",
    "Map.setCenter(-122.1899, 37.5010, 10)\n",
    "# San Francisco Bay\n",
    "Map.addLayer(image, vizParams, \"False color composite\")\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "57",
   "metadata": {},
   "outputs": [],
   "source": [
    "js_snippet = \"\"\"\n",
    "\n",
    "// Load an image.\n",
    "var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');\n",
    "\n",
    "// Create an NDWI image, define visualization parameters and display.\n",
    "var ndwi = image.normalizedDifference(['B3', 'B5']);\n",
    "var ndwiViz = {min: 0.5, max: 1, palette: ['00FFFF', '0000FF']};\n",
    "Map.addLayer(ndwi, ndwiViz, 'NDWI', false);\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.js_snippet_to_py(js_snippet)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap\n",
    "\n",
    "Map = geemap.Map()\n",
    "\n",
    "# Load an image.\n",
    "image = ee.Image(\"LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318\")\n",
    "\n",
    "# Create an NDWI image, define visualization parameters and display.\n",
    "ndwi = image.normalizedDifference([\"B3\", \"B5\"])\n",
    "ndwiViz = {\"min\": 0.5, \"max\": 1, \"palette\": [\"00FFFF\", \"0000FF\"]}\n",
    "Map.addLayer(ndwi, ndwiViz, \"NDWI\", False)\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap\n",
    "\n",
    "Map = geemap.Map()\n",
    "\n",
    "# Load an image.\n",
    "image = ee.Image(\"LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318\")\n",
    "\n",
    "# Create an NDWI image, define visualization parameters and display.\n",
    "ndwi = image.normalizedDifference([\"B3\", \"B5\"])\n",
    "ndwiViz = {\"min\": 0.5, \"max\": 1, \"palette\": [\"00FFFF\", \"0000FF\"]}\n",
    "Map.addLayer(ndwi, ndwiViz, \"NDWI\", False)\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap\n",
    "\n",
    "Map = geemap.Map()\n",
    "ee.Initialize()\n",
    "\n",
    "# Load an image.\n",
    "image = ee.Image(\"LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318\")\n",
    "\n",
    "# Create an NDWI image, define visualization parameters and display.\n",
    "ndwi = image.normalizedDifference([\"B3\", \"B5\"])\n",
    "ndwiViz = {\"min\": 0.5, \"max\": 1, \"palette\": [\"00FFFF\", \"0000FF\"]}\n",
    "Map.addLayer(ndwi, ndwiViz, \"NDWI\", False)\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62",
   "metadata": {},
   "source": [
    "## Use shapefiles"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64",
   "metadata": {},
   "outputs": [],
   "source": [
    "countries_shp = \"../data/countries.shp\"\n",
    "countries = geemap.shp_to_ee(countries_shp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "65",
   "metadata": {},
   "outputs": [],
   "source": [
    "countries_shp = \"../data/countries.shp\"\n",
    "countries = geemap.shp_to_ee(countries_shp)\n",
    "Map.addLayer(countries, {}, \"Countries\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66",
   "metadata": {},
   "outputs": [],
   "source": [
    "states_shp = \"../data/us_states.shp\"\n",
    "states = geemap.shp_to_ee(states_shp)\n",
    "Map.addLayer(states, {}, \"US States\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67",
   "metadata": {},
   "outputs": [],
   "source": [
    "cities_shp = \"../data/us_cities.shp\"\n",
    "cities = geemap.shp_to_ee(cities_shp)\n",
    "Map.addLayer(cities, {}, \"US Cities\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "68",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.ee_to_shp(countries, filename=\"../data/countries_new.shp\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.ee_export_vector(states, filename=\"../data/states.csv\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70",
   "metadata": {},
   "source": [
    "## Create Landsat timelapse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72",
   "metadata": {},
   "outputs": [],
   "source": [
    "label = \"Urban Growth in Las Vegas\"\n",
    "Map.add_landsat_ts_gif(\n",
    "    label=label,\n",
    "    start_year=1985,\n",
    "    bands=[\"Red\", \"Green\", \"Blue\"],\n",
    "    font_color=\"white\",\n",
    "    frames_per_second=10,\n",
    "    progress_bar_color=\"blue\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73",
   "metadata": {},
   "source": [
    "## Use time-series inspector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "74",
   "metadata": {},
   "outputs": [],
   "source": [
    "naip_ts = geemap.naip_timeseries(start_year=2009, end_year=2018)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75",
   "metadata": {},
   "outputs": [],
   "source": [
    "layer_names = [\"NAIP \" + str(year) for year in range(2009, 2019)]\n",
    "print(layer_names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "76",
   "metadata": {},
   "outputs": [],
   "source": [
    "naip_vis = {\"bands\": [\"N\", \"R\", \"G\"]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map.ts_inspector(\n",
    "    left_ts=naip_ts,\n",
    "    right_ts=naip_ts,\n",
    "    left_names=layer_names,\n",
    "    right_names=layer_names,\n",
    "    left_vis=naip_vis,\n",
    "    right_vis=naip_vis,\n",
    ")\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78",
   "metadata": {},
   "source": [
    "## Export images"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80",
   "metadata": {},
   "outputs": [],
   "source": [
    "image = ee.Image(\"LANDSAT/LE7_TOA_5YEAR/1999_2003\")\n",
    "\n",
    "landsat_vis = {\"bands\": [\"B4\", \"B3\", \"B2\"], \"gamma\": 1.4}\n",
    "Map.addLayer(image, landsat_vis, \"LE7_TOA_5YEAR/1999_2003\", True, 0.7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Draw any shapes on the map using the Drawing tools before executing this code block\n",
    "feature = Map.draw_last_feature\n",
    "\n",
    "if feature is None:\n",
    "    geom = ee.Geometry.Polygon(\n",
    "        [\n",
    "            [\n",
    "                [-115.413031, 35.889467],\n",
    "                [-115.413031, 36.543157],\n",
    "                [-114.034328, 36.543157],\n",
    "                [-114.034328, 35.889467],\n",
    "                [-115.413031, 35.889467],\n",
    "            ]\n",
    "        ]\n",
    "    )\n",
    "    feature = ee.Feature(geom, {})\n",
    "\n",
    "roi = feature.geometry()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "82",
   "metadata": {},
   "outputs": [],
   "source": [
    "out_dir = os.path.join(os.path.expanduser(\"~\"), \"Downloads\")\n",
    "filename = os.path.join(out_dir, \"landsat.tif\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.ee_export_image(\n",
    "    image, filename=filename, scale=90, region=roi, file_per_band=False\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.ee_export_image(\n",
    "    image, filename=filename, scale=90, region=roi, file_per_band=True\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85",
   "metadata": {},
   "outputs": [],
   "source": [
    "loc = ee.Geometry.Point(-99.2222, 46.7816)\n",
    "collection = (\n",
    "    ee.ImageCollection(\"USDA/NAIP/DOQQ\")\n",
    "    .filterBounds(loc)\n",
    "    .filterDate(\"2008-01-01\", \"2020-01-01\")\n",
    "    .filter(ee.Filter.listContains(\"system:band_names\", \"N\"))\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86",
   "metadata": {},
   "outputs": [],
   "source": [
    "out_dir = os.path.join(os.path.expanduser(\"~\"), \"Downloads\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87",
   "metadata": {},
   "outputs": [],
   "source": [
    "geemap.ee_export_image_collection(collection, out_dir=out_dir)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
